<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ include file="/jsp/common/common.jsp"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link href="<c:url value="/static/fullcalendar/fullcalendar.css"/>"
	rel='stylesheet' />
<link
	href="<c:url value="/static/fullcalendar/fullcalendar.print.css"/>"
	rel='stylesheet' media='print' />
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<link rel="Stylesheet" type="text/css"
	href="<c:url value="/static/css/jquery.ui.css"/>" />
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/Loading.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/showMsg.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/listBox/jquery.clever.listbox.js"/>"></script>
<script src="<c:url value="/static/fullcalendar/lib/moment.min.js"/>"></script>
<script src="<c:url value="/static/fullcalendar/fullcalendar.min.js"/>"></script>
<script src="<c:url value="/static/fullcalendar/lang-all.js"/>"></script>
<script type="text/javascript"
    src="<c:url value="/jsp/supplier/webInMaterValue.js"/>"></script>
<script>
	var dataLeft;

	function initList(listDisplayEId) {
		$('#' + listDisplayEId).datagrid(
				{
					url : "<c:url value="/supplier/listSupplierCost.do"/>",
					nowrap : false,
					striped : true,
					collapsible : true,
					remoteSort : true,
					notSelectByRow : false,
					onLoadError : function() {
						$.messager.alert('错误', '获取数据失败，请与管理员联系！', 'error');
					},
					toolbar : [ 
					{
						id : listDisplayEId + '_btn_add',
						text : '批量检索最后一次报价',
						iconCls : 'icon-add',
						handler : function() {
							batchSearchLastCost();
						}
					},{
                        id : listDisplayEId + '_btn_add',
                        text : '批量检索入库单价格',
                        iconCls : 'icon-add',
                        handler : function() {
                            batchSearchLastCostForStore();
                        }
                    },{
                        id : listDisplayEId + '_btn_add',
                        text : '批量导入进货价格并计算出货价格',
                        iconCls : 'icon-add',
                        handler : function() {
                            $('#listDisplay').datagrid('scrollTo', 10);//获取当前编辑器
                        	var r=confirm("确认批量导入报价，并生成价格？")
                        		if(r){
                        			deal();
                        		}
                        }
                    }
					/* ,{
                        id : listDisplayEId + '_btn_add',
                        text : '仅导入进货价格',
                        iconCls : 'icon-add',
                        handler : function() {
                            var r=confirm("确认批量导入报价？")
                                if(r){
                                	dealOnlyCost();
                                }
                        }
                    } */ ],
                    onClickCell:function(rowIndex,field,value){
                    		$(".myrad").prop("checked",false);
                            $(".myrad").eq(rowIndex).prop("checked",true);
                            $('#listDisplay').datagrid('beginEdit', rowIndex);
                            var ed = $('#listDisplay').datagrid('getEditor', {index:rowIndex,field:'materValue'});//获取当前编辑器
                            $(ed.target).focus();//获取焦点
                            $(ed.target).select();//获取焦点
                    },
					onLoadSuccess : function() {
						$('#listDisplay').datagrid('clearSelections');
	                      $('#listDisplay').datagrid('scrollTo',0);

						
					}  ,
					rowStyler: function(index,row){
				        if (row['submitCostFlag'] == ''|| row['submitCostFlag'] == 0 ||row['submitCostFlag'] == '0') {
                            return 'background-color:#FF8F59;';
                        }
					}
				});
	};

	function excel() {
		$('#AddFoodForm').form('submit', {
			url : '<c:url value='/supplier/importSupMaterValueCost.do'/>',
			onSubmit : function()//提交按钮相应函数
			{
				return $('#AddFoodForm').form('validate');
			},
			success : function(data) {
				data = eval('(' + data + ')');
				var msgsuccess = data.success + "";
				if (data.success) {
					Loading.Hide();
					$.messager.alert('系统提示', '导入成功', 'info', function() {
						window.close();
					});
				} else {
					var message = "";
					if (data.msg == "msg001") {
						message = "文件不能为空，请选择文件。";
					} else if (data.msg == "msg002") {
						message = "表格内容不正确，没有填写每单位价格。";
					} else if (data.msg == "msg003") {
						message = "日期格式不正确请按照  yyyy-MM-dd 来填写，并保证长度为10位。";
					} else if (data.msg == "msg004") {
						message = "价格格式不正确。";
					} else if (data.msg == "locked") {
						message = "正在提交中或其他人员提交中，请不要连续操作。";
					}
					$.messager.alert("提示", message, 'warning');
				}
			},
			error : function() {
				$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
				return;
			}
		});
	}
	$(document).ready(function() {
		init()
		initList("listDisplay");
	    setInterval("visitSession()", "200000");
	});

	function init() {
		$('#date').datebox({
			required : true,
			onSelect : function(date) {
				/* alert(date.getFullYear() + ":" + (date.getMonth() + 1)
						+ ":" + date.getDate());
				initCalendar(); */
				searchInfo();
			}

		});
	}
	function searchInfo() {
		if ($('#date').datebox('getValue') == '') {
			alert("日期不能为空");
		} else {
			$('#listDisplay').datagrid('load', {
				initFlag : 1,
				date : $('#date').datebox('getValue')
			});
		}
	}
	function beginEditList(rows, list, id) {
		for (var i = 0; i < rows.length; i++) {
			var rowIndex = $(list).datagrid('getRowIndex', rows[i][id]);
			$(list).datagrid('beginEdit', rowIndex);
		}
	}
	
	function batchSearchLastCost(){
        $('#listDisplay').datagrid('loading'); 
        
		var rows = $('#listDisplay').datagrid('getSelections');      
		
        if(rows.length == 0){
            $.messager.alert('提示','请选择一条记录操作！','info');
        } else {
        	//var turnoverList = new Array();
            //var jsonFater;
            for (var i = 0; i < rows.length; i++) {
            	//var jsonSun = "{materId:'" + rows[i]['materId'] + "'}";
                //turnoverList.push(jsonSun);
                
            	searchValueAjax(rows[i]['materId'],false);
            }
           
        }
        alert("检索完毕");
        $('#listDisplay').datagrid('loaded'); 

	}

    function batchSearchLastCostForStore(){
        $('#listDisplay').datagrid('loading'); 
        
        var rows = $('#listDisplay').datagrid('getSelections');      
        
        if(rows.length == 0){
            $.messager.alert('提示','请选择一条记录操作！','info');
        } else {
            //var turnoverList = new Array();
            //var jsonFater;
            for (var i = 0; i < rows.length; i++) {
                //var jsonSun = "{materId:'" + rows[i]['materId'] + "'}";
                //turnoverList.push(jsonSun);
                searchValueAjaxForStore(rows[i]['materId'],rows[i]['materLevel'],false);
            }
           
        }
        alert("检索完毕");
        $('#listDisplay').datagrid('loaded'); 

    }
	
	//添加信息按钮响应函数
	//var xhr;
	function deal() {

		//var rows = $('#listDisplay').datagrid('getRows');
		              $('#listDisplay').datagrid('loading'); 

		var rows = $('#listDisplay').datagrid('getSelections');      
        if(rows.length == 0){
            $.messager.alert('提示','请选择一条记录操作！','info');
            return;
        } else {
		for (var i = 0; i < rows.length; i++) {
			var rowIndex = $('#listDisplay').datagrid('getRowIndex',
					rows[i]['materId']);
			$('#listDisplay').datagrid('endEdit', rowIndex);
			if (!isNumber(rows[i]['materValue'])) {
				$.messager.alert("提示",
						"'" + rows[i]['materName'] + "'金额请填写数字！", 'info');
				beginEditList(rows, '#listDisplay', 'materId');
				
		        $('#listDisplay').datagrid('loaded'); 
		       
				return;
			}
			
			if (Number(rows[i]['materValue'])==0 ) {
	            $.messager.alert("提示",
	                    "'" + rows[i]['materName'] + "'金额不能为零！", 'info');
	            $('#listDisplay').datagrid('beginEdit', rowIndex);
	            $('#listDisplay').datagrid('loaded'); 
	            return;
	           
	        }
			
			//校验价格 效率差
			/* if(!checkMaterCost(rows[i]['materId'],rows[i]['materValue'])){
                //$.messager.alert("提示",rows[i]['materId']+"：'" + rows[i]['materName'] + "'进货价钱小于最低值或者大于最高值！", 'info');
                beginEditList(rows, '#listDisplay', 'materId');
                $('#listDisplay').datagrid('loaded'); 
                return ;
            } */
		}
		//生成json数据
		var turnoverList = new Array();
		var jsonFater;

		for (var i = 0; i < rows.length; i++) {
			var jsonSun = "{materId:'" + rows[i]['materId'] + "',materLevel:'"
					+ rows[i]['materLevel'] + "',materValueCost:'"
					+ rows[i]['materValue'] + "',date:'"
					+ $('#date').datebox('getValue') + "'}";
			turnoverList.push(jsonSun);
		}
		jsonFater = JSON.stringify(turnoverList);
		document.getElementById("materJson").value = jsonFater;
		$('#AddFoodForm')
				.form(
						'submit',
						{
							url : '<c:url value='/supplier/importSupMaterValueCostForWeb.do'/>', //查询提交路径
							onSubmit : function()//提交按钮相应函数
							{
								return $('#AddFoodForm').form('validate');
							},
							success : function(data) {
								data = eval("(" + data + ")");
								if (data.success) {
									$.messager.alert("提示", "提交成功！", 'info');
	                                $('#listDisplay').datagrid('load'); 
									$('#listDisplay').datagrid('clearSelections'); 

								} else {
									var message = "";
									if (data.msg == "locked") {
										message = "正在导入，请稍后再试。";
									} else if (data.msg == "msg001") {
										message = "选择材料的时间已过，请联系采购部。";
									}
									$.messager.alert("提示", message, 'warning');
								}
							},
							error : function() {
								$('#listDisplay').datagrid('loaded'); 
								$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
								return;
							}
						});
        }
	}
	
	//添加信息按钮响应函数
    //var xhr;
    function dealOnlyCost() {
        //var rows = $('#listDisplay').datagrid('getRows');
        var rows = $('#listDisplay').datagrid('getSelections');      
        if(rows.length == 0){
            $.messager.alert('提示','请选择一条记录操作！','info');
            return;
        } else {
        for (var i = 0; i < rows.length; i++) {
            var rowIndex = $('#listDisplay').datagrid('getRowIndex',
                    rows[i]['materId']);
            $('#listDisplay').datagrid('endEdit', rowIndex);
            if (!isNumber(rows[i]['materValue'])) {
                $.messager.alert("提示",
                        "'" + rows[i]['materName'] + "'金额请填写数字！", 'info');
                beginEditList(rows, '#listDisplay', 'materId');
                return;
            }
            //校验价格
            if(!checkMaterCost(rows[i]['materId'],rows[i]['materValue'])){
                //$.messager.alert("提示",rows[i]['materId']+"：'" + rows[i]['materName'] + "'进货价钱小于最低值或者大于最高值！", 'info');
                beginEditList(rows, '#listDisplay', 'materId');
                $('#listDisplay').datagrid('loaded'); 
                return ;
            }

        }
        //生成json数据
        var turnoverList = new Array();
        var jsonFater;

        for (var i = 0; i < rows.length; i++) {
            var jsonSun = "{materId:'" + rows[i]['materId'] + "',materLevel:'"
                    + rows[i]['materLevel'] + "',materValue:'"
                    + rows[i]['materValue'] + "',date:'"
                    + $('#date').datebox('getValue') + "'}";
            turnoverList.push(jsonSun);
        }
        jsonFater = JSON.stringify(turnoverList);
        document.getElementById("materJson").value = jsonFater;
        $('#AddFoodForm')
                .form(
                        'submit',
                        {
                            url : '<c:url value='/supplier/importSupMaterValueCostForOnlyCost.do'/>', //查询提交路径
                            onSubmit : function()//提交按钮相应函数
                            {
                                return $('#AddFoodForm').form('validate');
                            },
                            success : function(data) {
                                data = eval("(" + data + ")");
                                if (data.success) {
                                    $.messager.alert("提示", "提交成功！", 'info');
                                    
                                    for (var i = 0; i < rows.length; i++) {
                                        var rowIndex = $('#listDisplay').datagrid('getRowIndex',
                                                rows[i]['materId']);
                                        rows[i]['submitCostFlag'] = 1;
                                        $('#listDisplay').datagrid('endEdit', rowIndex);
                                        $('#listDisplay').datagrid('refreshRow', rowIndex);
                                        //$('#listDisplay').datagrid('getEditor', {index:rowIndex,field:'materValue'});
                                        $('#listDisplay').datagrid('beginEdit', rowIndex);
                                    }
                                } else {
                                    var message = "";
                                    if (data.msg == "locked") {
                                        message = "正在导入，请稍后再试。";
                                    } else if (data.msg == "msg001") {
                                        message = "选择材料的时间已过，请联系采购部。";
                                    }
                                    $.messager.alert("提示", message, 'warning');
                                }
                            },
                            error : function() {
                                $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                                return;
                            }
                        });
        }
    }
	function  dealOneformatter(val,rowData,rowIndex){
        return '<a href="javascript:void(0)" onclick="dealOne(\'' + rowData.materValue + '\',\''+ rowData.materName + '\',\''+ rowData.materId + '\',\''+ rowData.materLevel + '\',\'' + rowIndex +  '\',1)">导入价格</a>  '
    }
	function end(rowIndex){
       // 
	}
	function stylechang(e){

		var a = e.parentNode.parentNode.parentNode;
        
        $(a).children().css("background-color", "#FFFFFF");
        alert(2);
	}
	function dealOne(rowDataMaterValue,rowDataMaterName,rowDataMaterId,rowDataMaterLevel,rowIndex,flagCheck) {
		$('#listDisplay').datagrid('endEdit', rowIndex);

        //$('#listDisplay').datagrid('loading'); 
        //获取value
        var row = $('#listDisplay').datagrid('getData').rows[rowIndex];
        if (!isNumber(row.materValue)) {
            $.messager.alert("提示",
                    "'" + rowDataMaterName + "'金额请填写数字！", 'info');
            //$('#listDisplay').datagrid('beginEdit', rowIndex);
            $('#listDisplay').datagrid('loaded'); 
            return;
           
        }
        
        if (Number(row.materValue)==0 ) {
            $.messager.alert("提示",
                    "'" + rowDataMaterName + "'金额不能为零！", 'info');
            //$('#listDisplay').datagrid('beginEdit', rowIndex);
            $('#listDisplay').datagrid('loaded'); 
            return;
           
        }
        /* if(!checkMaterCost(row.materId,row.materValue)){
            return ;
        } */
        //生成json数据
        var turnoverList = new Array();
        var jsonFater;
        var jsonSun = "{materId:'" + rowDataMaterId + "',materLevel:'"
                    + rowDataMaterLevel + "',materValueCost:'"
                    + row.materValue + "',date:'"
                    + $('#date').datebox('getValue') + "'}";
        turnoverList.push(jsonSun);
        jsonFater = JSON.stringify(turnoverList);
        document.getElementById("materJson").value = jsonFater;
        /* $('#listDisplay').datagrid('beginEdit', rowIndex);
        var ed = $('#listDisplay').datagrid('getEditor', {index:rowIndex,field:'materValue'});//获取当前编辑器
        $(ed.target).focus();//获取焦点
        $(ed.target).select(); */

        $('#AddFoodForm')
                .form(
                        'submit',
                        {
                            url : '<c:url value='/supplier/importSupMaterValueCostForWeb.do'/>', //查询提交路径
                            onSubmit : function()//提交按钮相应函数
                            {
                                return $('#AddFoodForm').form('validate');
                            },
                            success : function(data) {
                                data = eval("(" + data + ")");
                                if (data.success) {
                                	if(flagCheck=='1'){
                                        row['submitCostFlag'] = 1;
                                        $('#listDisplay').datagrid('endEdit', rowIndex);
                                        $('#listDisplay').datagrid('refreshRow', rowIndex);
                                    }
                                   

                                } else {
                                    var message = "";
                                    if (data.msg == "locked") {
                                        message = "正在导入，请稍后再试。";
                                    } else if (data.msg == "msg001") {
                                        message = "选择材料的时间已过，请联系采购部。";
                                    }
                                    $.messager.alert("提示", message, 'warning');
                                    $('#listDisplay').datagrid('loaded'); 

                                }
                            },
                            error : function() {
                                $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                                $('#listDisplay').datagrid('loaded'); 

                                return;
                            }
                        });
        

    }

        

	
	function initCalendar() {

		$('#calendar')
				.fullCalendar(
						{
							header : {
								left : 'prev,next today',
								center : 'title',
								right : 'month'
							},
							lang : 'zh-cn',
							defaultDate : $('#date').datebox('getValue'),
							selectable : true,
							selectHelper : true,
							select : function(start, end) {
								var title = prompt('Event Title:');
								var eventData;
								if (title) {
									eventData = {
										title : title,
										start : start,
										end : end
									};
									$('#calendar').fullCalendar('renderEvent',
											eventData, true); // stick? = true
								}
								$('#calendar').fullCalendar('unselect');
							},
							editable : false,
							eventLimit : true, // allow "more" link when too many events
							events : {
								url : "<c:url value="/supplier/webSupplierInValueJsonForState.do"/>"
										+ '?date='
										+ $('#date').datebox('getValue'),
								error : function() {
									$('#script-warning').show();
								}
							}
						});

	}
	
	function colourValue(value, row, index) {
        /* if (row['materValue'] == ''||row['materValue'] ==0 ||row['materValue'] =='0'||row['materValue'] =='0.0'||row['materValue'] =='0.00') {
            return 'background-color:#FF8F59;';
        } */
        //alert(row['submitCostFlag']);
        if (row['submitCostFlag'] == ''|| row['submitCostFlag'] == 0 ||row['submitCostFlag'] == '0') {
            return 'background-color:#FF8F59;';
        }
    }
	//检索最后价格
	function  searchValue(val,rowData,rowIndex){
        return '<a href="javascript:void(0)" onclick="searchValueAjax(\'' + rowData.materId+ '\',\'' + rowData.materValue  +'\',\''+'true'+ '\')">'+val+'</a>  '
    }
	function searchValueAjax(materId,materValueFlag,focusFlag) {
		var valuemater;
		$.ajax(
			{
			type:'post',
			//async : false,
			url:"<c:url value='/supplier/getMaterValueCostByMaterId.do'/>"+"?materId="+materId,dataType:"json",//设置查询参数及提交路径
            success:function(data){
            	valuemater=data.materValueCost;
            	
            	 var rowIndex = $('#listDisplay').datagrid('getRowIndex',materId);
                 $('#listDisplay').datagrid('endEdit', rowIndex);
                 $('#listDisplay').datagrid('updateRow',{
                     index: rowIndex,
                     row: {
                         materValue: valuemater,
                     }
                 });
                 if(focusFlag=='true'){
                	 $('#listDisplay').datagrid('refreshRow', rowIndex);
                     $('#listDisplay').datagrid('beginEdit', rowIndex);
                	 var ed = $('#listDisplay').datagrid('getEditor', {index:rowIndex,field:'materValue'});//获取当前编辑器
                     $(ed.target).focus();//获取焦点
                     $(ed.target).select();//获取焦点

                 }
                
                 
                /*  $('#listDisplay').datagrid({
                	    rowStyler: function(index,row){
                	        if (index == rowIndex){
                	            return 'background-color:#FF8F59;';
                	        }
                	    }
                	}); */

                 
            },
            error:function(){
                $('#listDisplay').datagrid('loaded'); 
            $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
            }
        });
        
    }
	//检索库存入库单价格
	function  searchValueForStore(val,rowData,rowIndex){
        return '<a href="javascript:void(0)" onclick="searchValueAjaxForStore(\'' + rowData.materId+ '\',\'' + rowData.materLevel  +'\',\''+'true'+ '\')">'+'检索入库单价格'+'</a>  '
    }
    function searchValueAjaxForStore(materId,materLevel,focusFlag) {
        var valuemater;
        var orderDate = $('#date').datebox('getValue');
        
        $.ajax(
            {
            type:'post',
            //async : false,
            url:"<c:url value='/distributor/getMaterValueUnitFromOrderDistributorMaterRealPo.do'/>"+"?ordMaterId="+materId+"&ordMaterLevel="+materLevel+"&ordDate="+orderDate,dataType:"json",//设置查询参数及提交路径
            success:function(data){
                valuemater=data.materValueCost;
                
                 var rowIndex = $('#listDisplay').datagrid('getRowIndex',materId);
                 $('#listDisplay').datagrid('endEdit', rowIndex);
                 $('#listDisplay').datagrid('updateRow',{
                     index: rowIndex,
                     row: {
                         materValue: valuemater,
                     }
                 });
                 if(focusFlag=='true'){
                     $('#listDisplay').datagrid('refreshRow', rowIndex);
                     $('#listDisplay').datagrid('beginEdit', rowIndex);
                     var ed = $('#listDisplay').datagrid('getEditor', {index:rowIndex,field:'materValue'});//获取当前编辑器
                     $(ed.target).focus();//获取焦点
                     $(ed.target).select();//获取焦点

                 }
                
                 
                /*  $('#listDisplay').datagrid({
                        rowStyler: function(index,row){
                            if (index == rowIndex){
                                return 'background-color:#FF8F59;';
                            }
                        }
                    }); */

                 
            },
            error:function(){
                $('#listDisplay').datagrid('loaded'); 
            $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
            }
        });

        
    }
	function checkMaterCost(materId,materValue){
		var flag ;

        var str = "materId="+materId+"&materValue="+materValue; 
        $.ajax({
        	type:'post',
        	async: false, 
        	url:"<c:url value='/materCheck/checkMaterCost.do'/>"+"?"+str,dataType:"json",//设置查询参数及提交路径
            success:function(data){
                if(data.success){
                    flag = true;
                }else{
                	flag = false;
                    $('#listDisplay').datagrid('loaded'); 

                    $.messager.alert("提示", data.msg, 'warning');
                }
            },
            error:function(){
            $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
            }
        });
        return flag;
    };
    
    function  goDetailedContent(val,rowData,rowIndex){
        return '<a href="javascript:void(0)" onclick="constructionManager(\'' + rowData.materId+ '\',\'' + $('#date').datebox('getValue')+ '\',\''+$('#date').datebox('getValue')+'\',\''+0+'\',\''+0 +'\')">'+'查看商店'+'</a>  '
    }
    function constructionManager(materId,ordDateStart,ordDateEnd,custIdAll,supId) {
        var new_win = window.open("<c:url value='/jsp/openIndexSun.jsp?url=/check/goCheckDetailedForAdmin.do'/>"+"?materId="+materId+"&ordDateStart="+ordDateStart+"&ordDateEnd="+ordDateEnd+"&custIdAll="+custIdAll+"&supId="+supId+"&user=sup","sun","width=1200px,height=580px,status=no,scrollbars=yes");
        new_win.focus();
    }
    //页面监听事件
    document.onkeydown=keyDownSearch;  
    function keyDownSearch(e) {  
        // 兼容FF和IE和Opera    
        var theEvent = e || window.event;    
        var code = theEvent.keyCode || theEvent.which || theEvent.charCode;    
        if (code == 38) {    
            //38上箭头
            arrowTop();//具体处理函数    
        } else if (code == 40){
            //40下箭头箭头
            arrowDown();//具体处理函数    
        } else if (code == 13){
            keyDeal();//具体处理函数    
        }
    }  
    function arrowTop(){
    	//根据焦点获得行
    	if(document.activeElement=="[object HTMLInputElement]"){
    	    var a = document.activeElement.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
    	    var rowIndex = $(a).attr("datagrid-row-index");
    		var rowIndexChange = Number(rowIndex)-Number(1);
    		$('#listDisplay').datagrid('beginEdit', rowIndexChange);
            var ed = $('#listDisplay').datagrid('getEditor', {index:rowIndexChange,field:'materValue'});//获取当前编辑器
            $(ed.target).focus();//获取焦点
            $(ed.target).select();//获取焦点
    	}
    }
    function arrowDown(){
    	//根据焦点获得行
        if(document.activeElement=="[object HTMLInputElement]"){
            var a = document.activeElement.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
            var rowIndex = $(a).attr("datagrid-row-index");
            var rowIndexChange = Number(rowIndex)+Number(1);
            $('#listDisplay').datagrid('beginEdit', rowIndexChange);
            var ed = $('#listDisplay').datagrid('getEditor', {index:rowIndexChange,field:'materValue'});//获取当前编辑器
            $(ed.target).focus();//获取焦点
            $(ed.target).select();//获取焦点

        }
    }
    function keyDeal(){
        //根据焦点获得行
        if(document.activeElement=="[object HTMLInputElement]"){
            var a = document.activeElement.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
            var rowIndexkey = $(a).attr("datagrid-row-index");
            var rowIndexChange = Number(rowIndexkey);
            arrowDown();

            var rows = $('#listDisplay').datagrid('getRows');      
                for (var i = 0; i < rows.length; i++) {
                    var rowIndex = $('#listDisplay').datagrid('getRowIndex',
                        rows[i]['materId']);
                    if(rowIndexChange==rowIndex ){
                        $('#listDisplay').datagrid('endEdit', rowIndex);
                        dealOne(rows[i]['materValue'] , rows[i]['materName'],rows[i]['materId'] ,rows[i]['materLevel'] , rowIndex);
                    }
                }
           $(a).children().css("background-color", "#FFFFFF")
            
        }
    }
</script>
</head>
<body>
	<table width="60%">
		<tr>
			<td>
				<form id="AddFoodForm" name="AddFoodForm" method="post"
					enctype="multipart/form-data">
					<div
						style="height: auto; width: 1180px; background: #fafafa; padding: 5px;"
						class="easyui-panel" title="属性列表" iconCls="icon-add"
						collapsible="true" minimizable="false" maximizable="false"
						closable="false">
						<table cellpadding="5">
							<tr>
								<td>日期</td>
								<td><input class="easyui-datebox" name="date" id="date"
									editable="false" data-options="required:true" /></td>
								<!-- <td><input type="button" onclick="searchInfo()" value="查询"></td> -->
								<td><input class="easyui-validatebox" type="hidden"
									name="idList" /></td>
								<td><input class="easyui-validatebox" type="hidden"
									name="excelList" /></td>
								<td><input class="easyui-validatebox" type="hidden"
									name="materJson" id='materJson' /></td>
							</tr>
						</table>
					</div>
				</form>

			</td>
		</tr>
		<tr style='display:none'>
			<td>
				<div
					style="height: auto; width: 600px; background: #fafafa; padding: 5px;display:none;"
					class="easyui-panel" title="日历列表" iconCls="icon-add"
					collapsible="true" minimizable="false" maximizable="false"
					closable="false">
					<div id='calendar'></div>
				</div>
			</td>
		</tr>
		<tr>
			<td>
				<table id="listDisplay" title="进货材料列表" iconCls="icon-list" height="450px"
					singleSelect="false" idField="materId" loadMsg="请稍候......"
					pagination="false" pageSize="20" sortName="materId"
					rownumbers="true" sortOrder="asc">
					<thead>
						<tr>
						    <th field="id" width="25" align="center"  checkbox="true"   >
                            </th> 
							<th field="materId" width="70" sortable="true"  >材料ID</th>
							<th field="materName" width="80" sortable="true"  >材料名</th>
							<th field="materLevel" width="80" sortable="true" hidden='true'   >等级</th>
							<th field="brands" width="70" sortable="true"   >品牌</th>
							<th field="specifications" width="70" sortable="true"   >规格</th>
							<th field="materTypeName" width="80" sortable="true"   >种类</th>
							<th field="materWeight" width="50" sortable="true"   >数量</th>
							<th field="unit" width="50" sortable="true"   >单位</th>
							<th field="materValue" width="80" sortable="true" editor="text"   >单位进货价格
							</th>
							<th field="content" width="120" sortable="true"    formatter="searchValue"  >检索最后报价
                            </th>
                            <th field="content2" width="120" sortable="true"    formatter="searchValueForStore"  >检索当日进货价
                            </th>
                            <th field="content1" width="80" sortable="true"    formatter="dealOneformatter"  >导入价格
                            </th>
                            <th field="submitCostFlag" width="120" sortable="true"    hidden="true"  >导入标记
                            </th>
                            <th field="content3" width="120" sortable="true"   formatter="goDetailedContent"  >查看商店
                            </th>
						</tr>
					</thead>
				</table>
			</td>
		</tr>

	</table>
</body>
</html>